package com.qingrongby.shop.service.impl;

import com.qingrongby.shop.model.Spu;
import com.qingrongby.shop.repository.SpuRepository;
import com.qingrongby.shop.service.SpuService;
import com.qingrongby.shop.vo.Paging;
import com.qingrongby.shop.vo.PagingDozer;
import com.qingrongby.shop.vo.SpuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @CLASSNAME SpuServiceImpl
 * @DESCRIPTION TODO
 * @AUTHOR hzp
 * @DATE 2020/6/24
 * @VERSION 1.0
 **/
@Service
public class SpuServiceImpl implements SpuService {

    @Autowired
    public SpuRepository spuRepository;

    @Override
    public PagingDozer<Spu, SpuVO> getLatestPagingSpu(Integer pageNum, Integer size) {
     Pageable pageable= PageRequest.of(pageNum,size);
//              Sort.by("").descending());
        Page<Spu> spuPage= spuRepository.findAll(pageable);
        PagingDozer<Spu,SpuVO> pagingDozer=new PagingDozer<>(spuPage,SpuVO.class);

        return pagingDozer;
    }
}
